#1#####
练习 = "hhh"
a = "hhhh"
.b = "hhhhh"

#2####
v <- c(1:10)
group <- c("a","a","a","b","b","a","a","c","b","b")
tapply(v, group)
tapply(v, group,mean)

#3####
v1 <- sample(1:20,10)
v2 <- sample(3:28,10)
data <- data.frame(v,v1,v2,group)

#4.1####
num <- sample(1:50,10, replace = TRUE)
count <- 0
for (i in num) {
  if (i > 10) {
    count <- count + 1
  }
}
print(count)

#4.2####
sort_out <-sort(num,decreasing = TRUE)
print(sort_out)


n <- length(num)
for (i in 1:(n - 1)) {
  swapped <- FALSE  
  for (j in 1:(n - i)) {
    if (num[j] < num[j + 1] ) {
      temp <- num[j]
      num[j] <- num[j + 1]
      num[j + 1] <- temp
      swapped <- TRUE   #标记发生交换
    }
  }
  if (!swapped) {
    break       #如果在一轮遍历中没有发生交换，说明排序完成
  }
}
print(num)